<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>核酸检测系统</title>
</head>
<body>
<h1>核酸检测系统</h1>
<form method="get" action="/" >
    <select th:name="hospitalId">
        <option th:value="0">----请选择----</option>
        <span th:each="h : ${hospital}">
            <option th:selected="${h.getId() eq hId}" th:value="${h.getId()}" th:text="${h.getName()}"></option>
        </span>
    </select>
    <input type="submit" th:value="查询"/>
</form>
<a class="aaa" th:href="@{/toAdd}">
    <button th:text="新增"></button>
</a>
<div>
    <table border="1">
        <tr>
            <th>被检测人</th>
            <th>被检测人手机号</th>
            <th>被检测人身份证号</th>
            <th>检测机构</th>
            <th>检测日期</th>
            <th>检测结果</th>
            <th>操作</th>
        </tr>
        <tr th:each="ma : ${page}">
            <td th:text="${ma.getAssayUser()}"></td>
            <td th:text="${ma.getPhone()}"></td>
            <td th:text="${ma.getCardNum()}"></td>
            <td th:text="${ma.getHospitalName()}"></td>
            <td th:text="${#dates.format(ma.getAssayTime(),'yyyy-MM-dd')}"></td>
            <td>
                <span th:if="${ma.getAssayResult() eq 0}" th:text="检测中"></span>
                <span th:if="${ma.getAssayResult() eq 1}" th:text="确诊" style="color: red"></span>
            </td>
            <td><a th:href="'javascript:void(0);'" th:text="确诊" th:onclick="'javascript:update('this','+${ma.getId()}')'" ></a></td>
        </tr>
    </table>
</div>

</body>
<script>
    $("table tr:nth-child(1)").css("backgroundColor","darkgray");
    $("table tr:nth-child(even)").css("backgroundColor","aliceblue");
    function update(a,id){
        let status = 0;
        let statusTxt = $(a).html();
        if(statusTxt === "确诊"){
            status = 0;
        }else{
            status = 1;
        }
        if(confirm("确认修改吗?")){
            $.post("/update",{"assayResult":status,"id":id},function (data){
                if(data > 0){
                    if(status === 0){
                        $(a).html("检测中").css("color","black");
                        $(a).parent().prev().html("确诊").css("color","red");
                    }
                }
            })
        }else{
            alert("已取消!");
        }
    }
</script>
</html>